package com.lujianfei.compose.ui.public

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Card
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.lujianfei.compose.entities.FuncInfo
import androidx.compose.foundation.lazy.items

@ExperimentalMaterialApi
@Composable
fun FunctionList(functions: ArrayList<FuncInfo>) {
    LazyColumn(
        verticalArrangement = Arrangement.spacedBy(15.dp)
    ) {
        item {
            Spacer(Modifier.size(0.dp))
        }
        items(functions) { func ->
            FuncItem(func)
        }
        item {
            Spacer(Modifier.size(0.dp))
        }
    }
}

@ExperimentalMaterialApi
@Composable
fun FuncItem(func: FuncInfo) {
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
            .padding(15.dp, 0.dp),
        backgroundColor = func.color,
        elevation = 2.dp,
        onClick = {
        }
    ) {
        Column(verticalArrangement = Arrangement.Center) {
            Text(
                text = func.name,
                modifier = Modifier.padding(15.dp, 0.dp, 0.dp, 0.dp),
                textAlign = TextAlign.Start,
                fontSize = MaterialTheme.typography.h5.fontSize,
                color = Color.White
            )
        }
    }
}